import React, { useEffect } from 'react'
import { useLocation, useNavigate } from 'react-router-dom'

function Hoc_login({ children }) {
    function Com() {
        let loction=useLocation()
        let token=localStorage.getItem('token')
        let navtion=useNavigate()
        let list=['/login']
        let falg=list.includes(loction.pathname)
        useEffect(()=>{
            if(!token&&!falg){
                navtion('/login')
            }
             
        },[token,loction])
        return children
    }
    return <Com></Com>
}

export default Hoc_login
